#pragma once
#include <map>
#include <GdiPlus.h>
using namespace Gdiplus;
using namespace std;

/// <summary>
/// Auto manage font (GDI+ object) resources.
/// </summary>
/// <remark>
/// None.
/// </remark>
class AFX_EXT_CLASS CPenLib
{
public:
	CPenLib(void);
	~CPenLib(void);

public:
	typedef struct tagPEN_PROPERTIES
	{
		int		nFlag;	/// use this variable to find font. 0 means unused.
		float	arrDashPattern[2];
		int		nDashPatternCount;
		tagPEN_PROPERTIES()
		{
			nDashPatternCount = 0;
			nFlag = 0;
		}
	}PEN_PROPERTIES;

public:
	// Release resource
	void FreePens();
	// Return the pointer of Pen object
	Pen* GetPen(float fPenWidth, COLORREF crPen, PEN_PROPERTIES& sProperties);
protected:
	// Create Pen object
	Pen* CreatePen(float fPenWidth, COLORREF crPen, PEN_PROPERTIES& sProperties);
protected:
	typedef pair<float,COLORREF> map_Pair1;
	typedef pair<map_Pair1, int> map_Pair2;
	typedef map<map_Pair2, Pen*> map_Pens;
	map_Pens m_mapPens;
};
